<?php

namespace App\Http\Controllers\XhAdmin;

use App\Http\Controllers\Admin\BaseController;
use App\Repository\XhApi\GridRepository;
use Illuminate\Http\Request;

// 宫格管理
class GridController extends BaseController
{
    private $repoist;

    public function __construct(GridRepository $repository)
    {
        $this->repoist = $repository;
    }


    public function index(Request $request)
    {
        $dataArr = $this->repoist->index($request->all(), $request->get('pageNum'), $request->get('pageSize'));

        if (1 == $request->get('pageNum') && is_array($dataArr)) {
            $dataArr['statusList'] = config('xh.switchStatus');
            $dataArr['listTypeList'] = config('xh.listType');
            $dataArr['ruleTypeList'] = config('xh.ruleType');
            $dataArr['apiSymbolList'] = config('xh.apiSymbol');
        }
        return $dataArr;
    }

    public function edit(Request $request)
    {
        if (!$request->get('id')) {
            return $this->returnMsg(1, '请传递id参数');
        }
        return $this->repoist->edit($request->all());
    }

    public function add(Request $request)
    {
        return $this->repoist->add($request->all());
    }

    public function del(Request $request, $id)
    {
        if (!$id) {
            return $this->returnMsg(1, '请传递参数');
        }
        return $this->repoist->del($id, $request->user->shop_id);
    }

    public function status(Request $request)
    {
        if (!$request->get('id')) {
            return $this->returnMsg(1, '请传递参数');
        }
        return $this->repoist->unifiedUpdateStatus($request->get('id'), $request->get('status'), $request->user->shop_id);
    }
}
